package com.cbg.archives.service.impl;

import com.cbg.archives.dto.ArchivesModularDTO;
import com.cbg.archives.entity.EsArchivesModular;
import com.cbg.archives.repository.IEsArchivesModularRepository;
import com.cbg.archives.service.IEsArchivesModularService;
import com.cbg.dto.DirectionsDTO;
import com.shuyuwl.core.enums.StatusEnum;
import com.shuyuwl.core.exception.SymServiceException;
import com.shuyuwl.core.service.impl.DaoServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * null serviceImpl
 *
 * @author wangjuzheng
 * @since 2019-10-16
 */
@Service
@Transactional(rollbackFor = SymServiceException.class)
public class EsArchivesModularServiceImpl extends DaoServiceImpl<EsArchivesModular, Long, IEsArchivesModularRepository> implements IEsArchivesModularService {

    @Resource
    private IEsArchivesModularRepository esArchivesModularRepository;

    @Override
    public Integer getMaxSort(Long archivesId, Byte status) {
        return esArchivesModularRepository.getMaxSort(archivesId, status);
    }

    @Override
    public EsArchivesModular findByIdAndStatus(Long id, Byte status) {
        return esArchivesModularRepository.findByIdAndStatus(id, status);
    }

    @Override
    public List<ArchivesModularDTO> selectedArchives(Long archivesId) {
        return esArchivesModularRepository.selectedArchives(archivesId, StatusEnum.OK.getCode(), StatusEnum.OK.getCode());
    }

    @Override
    public List<EsArchivesModular>  findByPidAndModularName(Long categoryId, String modularName) {
        return esArchivesModularRepository.findByArchivesIdAndAndNameAndStatus(categoryId,modularName,StatusEnum.OK.getCode());
    }

    @Override
    public void deleteByArchivesId(Long archivesId) {
        esArchivesModularRepository.deleteByArchivesId(archivesId,StatusEnum.DELETE.getCode());
    }

    @Override
    public List<DirectionsDTO> getDirectionsDTOs(Long archivesId) {
        return esArchivesModularRepository.getDirectionsDTOs(archivesId, StatusEnum.OK.getCode(), StatusEnum.DELETE.getCode());
    }

    @Override
    public void updateSort(List<Long> modularIds, int addSortNum) {
        esArchivesModularRepository.updateSort(modularIds,addSortNum,StatusEnum.OK.getCode());
    }
}
